package com.ruoyi.system.util;

import lombok.Data;

@Data
public class Result {

    private Integer code;  // 状态码
    private String msg;    // 消息
    private Object data;   // 数据

    /**
     * 成功返回结果
     * @param data 数据
     * @return Result
     */
    public static Result success(Object data) {
        Result result = new Result();
        result.setCode(200);
        result.setMsg("操作成功");
        result.setData(data);
        return result;
    }
    public static Result success(Integer code,Object data) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg("操作成功");
        result.setData(data);
        return result;
    }

    /**
     * 成功返回结果
     * @return Result
     */
    public static Result success() {
        return success(null);
    }

    /**
     * 失败返回结果
     * @param msg 错误信息
     * @return Result
     */
    public static Result error(String msg) {
        Result result = new Result();
        result.setCode(500);
        result.setMsg(msg);
        result.setData(null);
        return result;
    }

    /**
     * 失败返回结果
     * @param code 错误码
     * @param msg 错误信息
     * @return Result
     */
    public static Result error(Integer code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(null);
        return result;
    }
}
